package com.ruibang.glass.portal.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruibang.glass.common.domain.SuperviseNotice;
import com.ruibang.glass.portal.domain.NoticeReq;
import com.ruibang.glass.portal.entity.Notice;
import com.ruibang.glass.portal.mapper.NoticeMapper;
import com.teaming.cloud.framework2.common.model.ResultBody;
import com.teaming.cloud.framework2.common.pojo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 通知公告 服务实现类
 * </p>
 *
 * @author 此代码为自动生成
 * @since 2019-11-12
 */
@Service
public class NoticeService extends ServiceImpl<NoticeMapper, Notice> implements IService<Notice> {

    @Autowired
    private CommonService commonService;

    /***
     * 根据参数查询公告列表
     * @param noticeReq
     * @return
     */
    public ResultBody<PageResult<List<Notice>>> queryNotices(NoticeReq noticeReq) {
        if (noticeReq == null) {
            noticeReq = new NoticeReq();
        }
        final IPage<Notice> page = new Page<>(noticeReq.getPageNo(), noticeReq.getPageSize());
        List<Notice> notices = baseMapper.queryNotices(page, noticeReq);
        if (CollectionUtils.isNotEmpty(notices)) {
            page.setRecords(notices);
        }
        return ResultBody.success(new PageResult<>(page));
    }



    /***
     * 根据历史催办消息
     * @param noticeReq
     * @return
     */
    public ResultBody<List<Notice>> queryHistoryNotices(NoticeReq noticeReq) {
        if (noticeReq == null) {
            noticeReq = new NoticeReq();
        }
        return ResultBody.success(baseMapper.queryHistoryNotices(noticeReq));
    }


    /***
     *
     * @param ids
     * @return
     */
    public List<SuperviseNotice> queryNoticeByBusinessIds(List<String> ids) {
        return baseMapper.queryNoticeByBusinessIds(ids);
    }



    /***
     * 获取催办次数
     * @return
     */
    public Integer getSuperviseTimes(String businessId) {
        return baseMapper.getSuperviseTimes(businessId);
    }
}
